//
//  ViewController.m
//  UI04_HomeWork_01
//
//  Created by Bodi on 16/6/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "BodiButton.h"
@interface ViewController ()
@property(nonatomic, retain)UIImageView *cymbalImageView;
@property(nonatomic, retain)UIImageView *drinkImageView;
@property(nonatomic, retain)UIImageView *eatImageView;
@property(nonatomic, retain)UIImageView *fartImageView;
@property(nonatomic, retain)UIImageView *pieImageView;
@property(nonatomic, retain)UIImageView *scratchImageView;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatCat];
    [self creatButton];
    
    // Do any additional setup after loading the view, typically from a nib.
}
-(void)creatCat{
    UIImage *image = [UIImage imageNamed:@"angry_00.jpg"];
    UIImageView *view = [[UIImageView alloc]initWithImage:image];
    view.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:view];
    [view release];
    
}
- (void)creatButton{
    BodiButton *cymbalButton = [BodiButton button];
    cymbalButton.frame = CGRectMake(30, 400, 50, 50);
    NSString *path = [[NSBundle mainBundle]pathForResource:@"cymbal" ofType:@"png"];
    UIImage *cymbslImage = [UIImage imageWithContentsOfFile:path];
    [cymbalButton setImage:cymbslImage forState:UIControlStateNormal];
    [self.view addSubview:cymbalButton];
    [cymbalButton addTarget:self action:@selector(changeCymbal:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    BodiButton *drinkButton = [BodiButton button];
    drinkButton.frame = CGRectMake(30, 470, 50, 50);
    NSString *path1 = [[NSBundle mainBundle]pathForResource:@"drink" ofType:@"png"];
    UIImage *drinkImage = [UIImage imageWithContentsOfFile:path1];
    [drinkButton setImage:drinkImage forState:UIControlStateNormal];
    [self.view addSubview:drinkButton];
    [drinkButton addTarget:self action:@selector(changeDrink:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    BodiButton *eatButton = [BodiButton button];
    eatButton.frame = CGRectMake(30, 540, 50, 50);
    NSString *path2 = [[NSBundle mainBundle]pathForResource:@"eat" ofType:@"png"];
    UIImage *eatImage = [UIImage imageWithContentsOfFile:path2];
    [eatButton setImage:eatImage forState:UIControlStateNormal];
    [self.view addSubview:eatButton];
    [eatButton addTarget:self action:@selector(eatCymbal:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    BodiButton *fartButton = [BodiButton button];
    fartButton.frame = CGRectMake(330, 540, 50, 50);
    NSString *path3 = [[NSBundle mainBundle]pathForResource:@"fart" ofType:@"png"];
    UIImage *fartImage = [UIImage imageWithContentsOfFile:path3];
    [fartButton setImage:fartImage forState:UIControlStateNormal];
    [self.view addSubview:fartButton];
    [fartButton addTarget:self action:@selector(fartCymbal:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    BodiButton *pieButton = [BodiButton button];
    pieButton.frame = CGRectMake(330, 470, 50, 50);
    NSString *path4 = [[NSBundle mainBundle]pathForResource:@"pie" ofType:@"png"];
    UIImage *pieImage = [UIImage imageWithContentsOfFile:path4];
    [pieButton setImage:pieImage forState:UIControlStateNormal];
    [self.view addSubview:pieButton];
    [pieButton addTarget:self action:@selector(pieCymbal:) forControlEvents:UIControlEventTouchUpInside];

    
    
    BodiButton *scratchButton = [BodiButton button];
    scratchButton.frame = CGRectMake(330, 400, 50, 50);
    NSString *path5 = [[NSBundle mainBundle]pathForResource:@"scratch" ofType:@"png"];
    UIImage *scratchImage = [UIImage imageWithContentsOfFile:path5];
    [scratchButton setImage:scratchImage forState:UIControlStateNormal];
    [self.view addSubview:scratchButton];
    [scratchButton addTarget:self action:@selector(scratchCymbal:) forControlEvents:UIControlEventTouchUpInside];
    


}
- (void)changeCymbal:(BodiButton *)button{
    
        NSString *path = [[NSBundle mainBundle]pathForResource:@"cymbal_0" ofType:@"jpg"];
        UIImage *cymbalImage = [UIImage imageWithContentsOfFile:path];
        self.cymbalImageView = [[UIImageView alloc] initWithImage:cymbalImage];
       self.cymbalImageView.frame = [UIScreen mainScreen].bounds;
        [self.view addSubview:_cymbalImageView];
        [_cymbalImageView release];
        NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:13];
        for (int i = 0; i <= 12; i++) {
            NSString *name = [NSString stringWithFormat:@"cymbal_%d.jpg",i];
            UIImage *cymbalImage1 = [UIImage imageNamed:name];
            [mutableArray addObject:cymbalImage1];
    
    
        }
   
        self.cymbalImageView.animationImages = mutableArray;
       self.cymbalImageView.animationDuration = 2.0;
        self.cymbalImageView.animationRepeatCount = 1;
        [_cymbalImageView startAnimating];

    
    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(animationHiddn) userInfo:nil repeats:nil];
   
}
#pragma mark - 隐藏动画
- (void)animationHiddn{
    self.cymbalImageView.hidden = YES;

}


- (void)changeDrink:(BodiButton *)button{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"drink_0" ofType:@"jpg"];
    UIImage *cymbalImage = [UIImage imageWithContentsOfFile:path];
    self.drinkImageView = [[UIImageView alloc] initWithImage:cymbalImage];
    self.drinkImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:_drinkImageView];
    [_drinkImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:81];
    for (int i = 0; i <= 80; i++) {
        NSString *name = [NSString stringWithFormat:@"drink_%d.jpg",i];
        UIImage *cymbalImage1 = [UIImage imageNamed:name];
        [mutableArray addObject:cymbalImage1];
        
        
    }
    
    self.drinkImageView.animationImages = mutableArray;
    self.drinkImageView.animationDuration = 8.0;
    self.drinkImageView.animationRepeatCount = 1;
    [_drinkImageView startAnimating];
    
    
    [NSTimer scheduledTimerWithTimeInterval:8.0 target:self selector:@selector(drinkHiddn) userInfo:nil repeats:nil];


}
-(void)drinkHiddn{
    self.drinkImageView.hidden = YES;


}


- (void)eatCymbal:(BodiButton *)button{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"eat_00" ofType:@"jpg"];
    UIImage *cymbalImage = [UIImage imageWithContentsOfFile:path];
    self.eatImageView = [[UIImageView alloc] initWithImage:cymbalImage];
    self.eatImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:_eatImageView];
    [_eatImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:40];
    for (int i = 0; i <= 39; i++) {
        NSString *name = [NSString stringWithFormat:@"eat_%.2d.jpg",i];
        UIImage *cymbalImage1 = [UIImage imageNamed:name];
        [mutableArray addObject:cymbalImage1];
        
        
    }
    
    self.eatImageView.animationImages = mutableArray;
    self.eatImageView.animationDuration = 6.0;
    self.eatImageView.animationRepeatCount = 1;
    [_eatImageView startAnimating];
    
    
    [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(eatHiddn) userInfo:nil repeats:nil];
    
    
}
-(void)eatHiddn{
    self.eatImageView.hidden = YES;
    
    
}


- (void)fartCymbal:(BodiButton *)button{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"fart_00" ofType:@"jpg"];
    UIImage *cymbalImage = [UIImage imageWithContentsOfFile:path];
    self.fartImageView = [[UIImageView alloc] initWithImage:cymbalImage];
    self.fartImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:_fartImageView];
    [_fartImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:28];
    for (int i = 0; i <= 27; i++) {
        NSString *name = [NSString stringWithFormat:@"fart_%.2d.jpg",i];
        UIImage *cymbalImage1 = [UIImage imageNamed:name];
        [mutableArray addObject:cymbalImage1];
        
        
    }
    
    self.fartImageView.animationImages = mutableArray;
    self.fartImageView.animationDuration = 4.0;
    self.fartImageView.animationRepeatCount = 1;
    [_fartImageView startAnimating];
    
    
    [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(fartHiddn) userInfo:nil repeats:nil];
    
    
}
-(void)fartHiddn{
    self.fartImageView.hidden = YES;
    
    
}


- (void)pieCymbal:(BodiButton *)button{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"pie_00" ofType:@"jpg"];
    UIImage *cymbalImage = [UIImage imageWithContentsOfFile:path];
    self.pieImageView = [[UIImageView alloc] initWithImage:cymbalImage];
    self.pieImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:_pieImageView];
    [_pieImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:24];
    for (int i = 0; i <= 23; i++) {
        NSString *name = [NSString stringWithFormat:@"pie_%.2d.jpg",i];
        UIImage *cymbalImage1 = [UIImage imageNamed:name];
        [mutableArray addObject:cymbalImage1];
        
        
    }
    
    self.pieImageView.animationImages = mutableArray;
    self.pieImageView.animationDuration = 4.0;
    self.pieImageView.animationRepeatCount = 1;
    [_pieImageView startAnimating];
    
    
    [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(pieHiddn) userInfo:nil repeats:nil];
    
    
}
-(void)pieHiddn{
    self.pieImageView.hidden = YES;
    
    
}




- (void)scratchCymbal:(BodiButton *)button{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"scratch_00" ofType:@"jpg"];
    UIImage *cymbalImage = [UIImage imageWithContentsOfFile:path];
    self.scratchImageView = [[UIImageView alloc] initWithImage:cymbalImage];
    self.scratchImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:_scratchImageView];
    [_scratchImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:56];
    for (int i = 0; i <= 55; i++) {
        NSString *name = [NSString stringWithFormat:@"scratch_%.2d.jpg",i];
        UIImage *cymbalImage1 = [UIImage imageNamed:name];
        [mutableArray addObject:cymbalImage1];
        
        
    }
    
    self.scratchImageView.animationImages = mutableArray;
    self.scratchImageView.animationDuration = 4.0;
    self.scratchImageView.animationRepeatCount = 1;
    [_scratchImageView startAnimating];
    
    
    [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(scratchHiddn) userInfo:nil repeats:nil];
    
    
}
-(void)scratchHiddn{
    self.scratchImageView.hidden = YES;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
